#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 1e4 + 5;
const int MOD = 1e6 + 7;

int n, m;
int a[N], mx[N], flag[N];
ll dp[N], dp2;
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n;
  rep(i, 1, n) cin >> a[i];
  rep(i, 1, n) {
    if (a[i] > mx[i - 1])
      flag[i] = 1, mx[i] = a[i];
    else
      flag[i] = 0, mx[i] = mx[i - 1];
  }
  rep(i, 1, n - 1) dp[i] = i + 1;
  dp2 = a[n];
  per(i, n - 1, 1) {
    dp2 = ((a[i] - 1) * dp[mx[i - 1]] % MOD + dp2) % MOD;
    rep(j, 1, i - 1) dp[j] = (j * dp[j] % MOD + dp[j + 1]) % MOD;
  }
  cout << dp2;
  return 0;
}